home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 108_01 / rt11.c < prev    next >
Text File  |  1985-11-13  |  7KB  |  303 lines

  1. /*
  2.     RT-11 Adapter Package for CP/M
  3.  
  4.     Rev. 1.0 -- July 1980
  5.  
  6.     Rev. 1.1 -- March 1981 consisting of adding a valid system date
  7.             word to all files placed on the RT-11 disk and
  8.             putting the volume ID on a disk when the directory
  9.             is initialized.  This will keep RT-11 versions
  10.             later than V02C from choking.
  11.  
  12.     copyright (c) 1980, William C. Colley, III
  13.  
  14. The main-line routine is here, as are the individual command processors.
  15. */
  16.  
  17. #include "RT11.H"
  18.  
  19. /*
  20. Main program..........
  21. */
  22.  
  23. main()
  24. {
  25.     char temp[20], t, m, d, y;
  26.     puts("\nRT-11 File I/O Package -- Rev. 1.1 -- March 1981\n");
  27.     puts("     copyright (c) 1980, William C. Colley, III\N");
  28.     puts("\nPut RT-11 disk into drive B, and CP/M disk into drive A.\n");
  29.     puts("THIS IS IMPORTANT.  Hit CR when you're ready.");
  30.     while(1)
  31.     {
  32.         gets(temp);
  33.         if (temp[0] == '\0') break;
  34.         puts("Are you sure?");
  35.     }
  36.     puts("\nOK.\n");
  37.     bdos(INIT_BDOS);
  38.  
  39. /* Get system date word for later RT-11 versions. */
  40.  
  41.     do
  42.     {
  43.         puts("Today's date (mm/dd/yy)? ");
  44.         scanf("%d/%d/%d",&m,&d,&y);
  45.     }
  46.     while (m == 0 || m > 12 || d == 0 || d > 31 || y < 72 || y > 99);
  47.     sysdate = (m << 10) + (d << 5) + (y - 0110);
  48.  
  49.     while((t = getcom()) != 'Q')
  50.     {
  51.         switch (t)
  52.         {
  53.             case 'D':    list_dir();        break;
  54.             case 'E':    erase_file();        break;
  55.             case 'G':    get_file();        break;
  56.             case 'I':    init_disk();        break;
  57.             case 'P':    put_file();        break;
  58.             case 'R':    rename_file();        break;
  59.             case 'T':    type_file();        break;
  60.             default:
  61.                 puts("\nCommands available are:\n\n");
  62.                 puts("(D)irectory list\n");
  63.                 puts("(E)rase file on RT-11 disk\n");
  64.                 puts("(G)et file from RT-11 disk\n");
  65.                 puts("(I)initialize RT-11 disk\n");
  66.                 puts("(P)ut file onto RT-11 disk\n");
  67.                 puts("(R)ename file on RT-11 disk\n");
  68.                 puts("(Q)uit program\n");
  69.                 puts("(T)ype file on RT-11 disk\n");
  70.                 putchar('\n');
  71.                 break;
  72.         }
  73.     }
  74.     puts("\nReinsert system disk and type any key.");
  75.     getchar();
  76.     putchar('\n');
  77. }
  78.  
  79. /*
  80. Routine to erase a file on the RT-11 disk.
  81. */
  82.  
  83. erase_file()
  84. {
  85.     int file_name[3];
  86.     if (!get_RT_name("File to erase? ",file_name)) return;
  87.     if (!delete(file_name)) puts("Error -- file does not exist\n");
  88. }
  89.  
  90. /*
  91. Routine to rename a file on the RT-11 disk.
  92. */
  93.  
  94. rename_file()
  95. {
  96.     int old_name[3], new_name[3];
  97.     if (!get_RT_name("Old name of file? ",old_name)) return;
  98.     if (!get_RT_name("New name of file? ",new_name)) return;
  99.     if (!rename(old_name,new_name)) puts("Error -- file does not exist\n");
  100. }
  101.  
  102. /*
  103. Routine to list the directory on the RT-11 disk.
  104. */
  105.  
  106. list_dir()
  107. {
  108.     int t;
  109.     char s[4], volume_id[512], temp[13];
  110.     temp[12] = '\0';
  111.     emt_375(READ,1,1,volume_id);
  112.     puts("\nVolume: ");
  113.     putstr(temp,&volume_id[236*2]);
  114.     puts(temp);
  115.     puts("  Owner: ");
  116.     putstr(temp,&volume_id[242*2]);
  117.     puts(temp);
  118.  
  119.     usrcom();
  120.     puts("\n\nName  .Ext   Blks    Date     Start    Extras\n\n");
  121.     do
  122.     {
  123.         while(*(dir_pointer + 1) != ENDSEG)
  124.         {
  125.             if (*(dir_pointer + 1) == PERM)
  126.             {
  127.                 print_name(dir_pointer + 2);
  128.                 printf("   %3o   ",_getword(dir_pointer,4));
  129.                 if (t = _getword(dir_pointer,6) & 0x7fff)
  130.                 {
  131.                     getmon(t >> 10,s);
  132.                     printf("%2d-%s-%2d   ",(t >> 5) & 037,
  133.                         s,(t & 037) + 0110);
  134.                 }
  135.                 else puts("            ");
  136.                 printf("%3o   ",file_start);
  137.                 for (t = 0; t < directory.extra_bytes; t++)
  138.                     printf("  %3o",*(dir_pointer+t+14));
  139.             }
  140.             else printf("< unused >   %3o               %3o",
  141.                 _getword(dir_pointer,4),file_start);
  142.             incr1();
  143.             putchar('\n');
  144.         }
  145.     }
  146.     while (nxblk());
  147. }
  148.  
  149. /*
  150. Function to get a file from the RT-11 disk onto the CP/M disk.
  151. */
  152.  
  153. get_file()
  154. {
  155.     char CP_file[20], xfer_buffer[512];
  156.     int t, RT_file[3], fd;
  157.     if (!get_RT_name("RT-11 file name? ",RT_file)) return;
  158.     puts("CP/M file name? ");
  159.     gets(CP_file);
  160.     if (CP_file[0] == '\0') sprint_name(RT_file,CP_file);
  161.     if (!lookup(RT_file))
  162.     {
  163.         puts("Error -- no source file\n");
  164.         return;
  165.     }
  166.     if ((fd = creat(CP_file)) == -1)
  167.     {
  168.         puts("Error -- could not create destination file\n");
  169.         return;
  170.     }
  171.     for (t = _getword(dir_pointer,4); t > 0; t--)
  172.     {
  173.         emt_375(READ,file_start++,1,xfer_buffer);
  174.         if (write(fd,xfer_buffer,4) == -1)
  175.         {
  176.             puts("Error -- CP/M disk full\n");
  177.             close(fd);
  178.             return;
  179.         }
  180.     }
  181.     close(fd);
  182. }
  183.  
  184. /*
  185. Routine to type an RT-11 file on the console.
  186. */
  187.  
  188. type_file()
  189. {
  190.     char c, xfer_buffer[512];
  191.     int file_name[3], i, j;
  192.     if (!get_RT_name("File to type? ",file_name)) return;
  193.     if (!lookup(file_name))
  194.     {
  195.         puts("Error -- file does not exist\n");
  196.         return;
  197.     }
  198.     for (i = _getword(dir_pointer,4); i > 0; i--)
  199.     {
  200.         emt_375(READ,file_start++,1,xfer_buffer);
  201.         for (j = 0; j < 512; j++)
  202.         {
  203.             if ((c = xfer_buffer[j]) == '\0' || c == ('Z' - 64))
  204.                 return;
  205.             putchar(c);
  206.         }
  207.     }
  208. }
  209.  
  210. /*
  211. Routine to put a file onto the RT-11 disk.
  212. */
  213.  
  214. put_file()
  215. {
  216.     int RT_file[3], fd, size;
  217.     char CP_file[20], xfer_buffer[512];
  218.     puts("CP/M file name? ");
  219.     gets(CP_file);
  220.     if (CP_file[0] == '\0') return;
  221.     if (!get_RT_name("RT-11 file name? ",RT_file)) return;
  222.     if ((fd = open(CP_file,0)) == -1)
  223.     {
  224.         puts("Error -- could not open source file\n");
  225.         return;
  226.     }
  227.     size = filesize(CP_file);
  228.     if ((file_start = enter(RT_file,size)) == 0) return;
  229.     while (--size >= 0)
  230.     {
  231.         if (read(fd,xfer_buffer,4) == -1)
  232.         {
  233.             puts("Error -- disk read on CP/M disk\n");
  234.             close(fd);
  235.             return;
  236.         }
  237.         emt_375(WRITE,file_start++,1,xfer_buffer);
  238.     }
  239.     close(fd);
  240.     klose(RT_file);
  241. }
  242.  
  243. /*
  244. Routine to initialize the directory on an RT-11 disk.
  245. */
  246.  
  247. init_disk()
  248. {
  249.     char temp[50], *gets();
  250.     unsigned volume_id[256];
  251.     puts("Are you sure you want to do this (Y/N)? ");
  252.     gets(temp);
  253.     if (temp[0] != 'Y')
  254.     {
  255.         puts("\t.....Aborted\n");
  256.         return;
  257.     }
  258.     setmem(&directory,1024,0);
  259.     puts("Number of directory segments (1 to 31)? ");
  260.     while (1)
  261.     {
  262.         scanf("%d",&directory.total_segments);
  263.         if (directory.total_segments > 0 &&
  264.             directory.total_segments < 32) break;
  265.         puts("Say again? ");
  266.     }
  267.     puts("Extra bytes per directory entry? ");
  268.     scanf("%d",&directory.extra_bytes);
  269.     directory.highest_segment = 1;
  270.     directory.first_block = (directory.highest_segment + 1) * 2 + 4;
  271.     directory.entries[1] = EMPTY;
  272.     _putword(directory.entries,4,488 - 2 * directory.total_segments);
  273.     directory.entries[15 + directory.extra_bytes] = ENDSEG;
  274.     segrw(WRITE,1);
  275.     setmem(volume_id,512,' ');
  276.     volume_id[0] = 0;
  277.     volume_id[233] = 1;
  278.     volume_id[234] = 6;
  279.     volume_id[235] = 0107251;
  280.     puts("Volume ID (CR for default)? ");
  281.     putstr(&volume_id[236], *gets(temp)=='\0' ? "RT11A" : temp);
  282.     puts("Owner name (CR for default)? ");
  283.     if (*gets(temp) != '\0') putstr(&volume_id[242], temp);
  284.     putstr(&volume_id[248], "DECRT11A");
  285.     emt_375(WRITE,1,1,volume_id);
  286.     puts("\t.....Done\n");
  287. }
  288.  
  289. /*
  290. Internal function in initialize directory routine to put up to 12 characters
  291. from a string into the core image of the volume ID block (block 1 on the disk).
  292. Note that this routine is an addition at Ver 1.0.
  293. */
  294.  
  295. putstr(buffer,string)
  296. char *buffer, *string;
  297. {
  298.     char i;
  299.     for (i = 12; i > 0 && *string != '\0'; i--)
  300.         *buffer++ = toupper(*string++);
  301. }
  302.  
  303.